package org.duanyu.shopping_admin_service.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.duanyu.shopping_common.pojo.Role;


@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    //根据id查询角色，查询出角色所拥有的权限
    Role findById(Long id);

    //根据id删除角色，角色的权限和管理员的角色也都会失去
    @Delete("delete from bz_role_permission where rid=#{rid}")
    void deleteRoleAllPermission(Long rid);

    //删除用户——角色表的相关数据
    @Delete("delete from bz_admin_role where rid=#{rid}")
    void deleteRoleAllAdmin(Long id);

    //给角色添加权限
    @Insert("insert into bz_role_permission values (#{rid},#{pid})")
    void addPermissionToRole(@Param("rid") Long rid,@Param("pid") Long pid);
}
